import { MigrationInterface, QueryRunner } from "typeorm";

export class UpdateTable2001751129383112 implements MigrationInterface {
    name = 'UpdateTable2001751129383112'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TABLE \`ah_article_content_share\` (\`id\` int NOT NULL AUTO_INCREMENT, \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updated_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`remark\` text NULL COMMENT '备注', \`content_id\` int NULL, \`user_id\` int NULL, INDEX \`IDX_3aef323b57d37c30f83cabd4ea\` (\`id\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
        await queryRunner.query(`ALTER TABLE \`ah_feedback\` CHANGE \`user_id\` \`user_id\` int NULL COMMENT '用户ID'`);
        await queryRunner.query(`ALTER TABLE \`ah_article_content_share\` ADD CONSTRAINT \`FK_b9e4e4cd37a9c066c52c77e9391\` FOREIGN KEY (\`content_id\`) REFERENCES \`ah_article_content\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`ah_article_content_share\` ADD CONSTRAINT \`FK_79a5d0252b235bf2d759d67efa0\` FOREIGN KEY (\`user_id\`) REFERENCES \`sys_user\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`ah_article_content_share\` DROP FOREIGN KEY \`FK_79a5d0252b235bf2d759d67efa0\``);
        await queryRunner.query(`ALTER TABLE \`ah_article_content_share\` DROP FOREIGN KEY \`FK_b9e4e4cd37a9c066c52c77e9391\``);
        await queryRunner.query(`ALTER TABLE \`ah_feedback\` CHANGE \`user_id\` \`user_id\` int NOT NULL COMMENT '用户ID'`);
        await queryRunner.query(`DROP INDEX \`IDX_3aef323b57d37c30f83cabd4ea\` ON \`ah_article_content_share\``);
        await queryRunner.query(`DROP TABLE \`ah_article_content_share\``);
    }

}
